package com.ruoyi.problem.controller;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.problem.pojo.AnswerDTO;
import com.ruoyi.problem.pojo.RewardVO;
import com.ruoyi.problem.service.AppProblemService;

import io.swagger.annotations.Api;

@RestController
@RequestMapping("/api/v1/problem")
@Api(tags = "【APP】问题解答相关接口") 
@CrossOrigin
public class AppProblemController {

	@Autowired
	private AppProblemService appProblemService;
	
	/**
	 * 	打赏咨询师
	 * @param rewardVO
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/getRewardConsultationOrder")
	public AjaxResult getRewardConsultationOrder(@RequestBody RewardVO rewardVO,HttpServletRequest request) {
		if(null == rewardVO) {
			return AjaxResult.error("支付无效，请选择支付方式再操作");
		}
		if(StringUtils.isEmpty(rewardVO.getDid())) {
			return AjaxResult.error("请选择开占卜结果");
		}
		if(StringUtils.isEmpty(rewardVO.getContent())) {
			return AjaxResult.error("请输入咨询问题");
		}
		if(null == rewardVO.getAmount()) {
			return AjaxResult.error("请输入金额");
		}
		if(null == rewardVO.getIsAnonymous()) {
			rewardVO.setIsAnonymous(0);
		}
		return appProblemService.getRewardConsultationOrder(rewardVO, request);
	}
	
	/**
	 * 	抢单池
	 * @param pageNo
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/getOrderGrabbingPool")
	public AjaxResult getOrderGrabbingPool(Integer pageNo,Integer type,HttpServletRequest request) {
		if(null == pageNo) {
			pageNo = 1;
		}
		if(null == type) {
			type = 1;
		}
		return appProblemService.getOrderGrabbingPool(pageNo, type, request);
	}
	
	/**
	 * 	解答详情
	 * @param id
	 * @param request
	 * @return
	 */
	@GetMapping(value = "/getAnswerDetail")
	public AjaxResult getAnswerDetail(Long id,HttpServletRequest request) {
		if(null == id) {
			return AjaxResult.error("请选择数据");
		}
		return appProblemService.getAnswerDetail(id, request);
	}
	
	/**
	 * 	回复用户提问
	 * @param answer
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/replyProblem")
	public AjaxResult replyProblem(@RequestBody AnswerDTO answer,HttpServletRequest request) {
		if(null == answer || null == answer.getId()) {
			return AjaxResult.error("请选择问题");
		}
		if(StringUtils.isEmpty(answer.getVoice()) || null == answer.getVoiceLength()) {
			return AjaxResult.error("请录制语音");
		}
		return appProblemService.replyProblem(answer, request);
	}
	
	/**
	 * 	采纳用户回复
	 * @param answer.id		解答列表的id
	 * @param request
	 * @return
	 */
	@PostMapping(value = "/adoptUserReply")
	public AjaxResult adoptUserReply(@RequestBody AnswerDTO answer,HttpServletRequest request) {
		if(null == answer || null == answer.getId()) {
			return AjaxResult.error("请选择回复数据");
		}
		return appProblemService.adoptUserReply(answer.getId(), request);
	}
	
	
}
